package cn.com.dhc.danlu.widget;

import android.content.Context;
import android.util.AttributeSet;

import cn.com.dhc.danlu.delegate.callback.IRefreshView;
import cn.com.dhc.danlu.widget.couponview.filterview.CouponFilterView;

/**
 * User: Geek_Soledad(wuhaiyang@danlu.com)
 * Date: 2016-09-22
 * Time: 15:02
 * Description:  对XRecyclerView进行包装
 * user: do not setLoadingListener otherwise BaseListDataDelegate callback will not take effect
 */
public class DanluCouponRecyclerView extends DanluRecyclerView {
    private CouponFilterView couponFilterView;

    public DanluCouponRecyclerView(Context context) {
        super(context);
        addDefaultRefreshListener();
    }

    public DanluCouponRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        addDefaultRefreshListener();
    }

    public DanluCouponRecyclerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        addDefaultRefreshListener();
    }

    public void setCouponFilterView(CouponFilterView couponFilterView) {
        this.couponFilterView = couponFilterView;
    }

    private void addDefaultRefreshListener() {
        setLoadingListener(this);
    }

    public void setRefreshView(IRefreshView mRefreshView) {
        this.mRefreshView = mRefreshView;
    }

    @Override
    public void onRefresh() {
        if (null != mRefreshView) {
            mRefreshView.onRefresh(true);
            if (null != couponFilterView) {
                couponFilterView.canClickChildView(false);
            }
        }
    }

    @Override
    public void onLoadMore() {
        if (null != mRefreshView) {
            mRefreshView.onRefresh(false);
            if (null != couponFilterView) {
                couponFilterView.canClickChildView(false);
            }
        }
    }
}
